import React from 'react';
import { Select } from 'antd'
const Option = Select.Option;

export default {
  formateDate(formats, timestamp) {

    formats = formats || 'Y-m-d';

    var zero = function (value) {
      if (value < 10) {
        return '0' + value;

      }
      return value;

    };

    var myDate = timestamp ? new Date(timestamp) : new Date();
    var year = myDate.getFullYear();
    var month = zero(myDate.getMonth() + 1);
    var day = zero(myDate.getDate());
    var hour = zero(myDate.getHours());
    var minite = zero(myDate.getMinutes());
    var second = zero(myDate.getSeconds());

    return formats.replace(/Y|m|d|H|i|s/ig, function (matches) {
      return ({
        Y: year,
        m: month,
        d: day,
        H: hour,
        i: minite,
        s: second
      })[matches];

    })
  },

  pagination(data,callback){
    return {
        onChange:(current)=>{
          console.log(current)
            callback(current)
        },
        current:data.result.page,
        pageSize:data.result.page_size,
        total: data.result.total_count,
        showTotal:()=>{
            return `共${data.result.total_count}条`
        },
        showQuickJumper:false
    }
},
  getOptionList(data) {
    if (!data) {
      return [];
    }
    let options = [] //[<Option value="0" key="all_key">全部</Option>];
    data.map((item) => {
      options.push(<Option value={item.id} key={item.id}>{item.name}</Option>)
    })
    return options;
  },
  updateSelectedItem(selectedRowKeys, selectedItem, selectedIds) {
    if (selectedIds) {
      this.setState({
        selectedRowKeys,
        selectedItem,
        selectedIds
      })
    } else {
      this.setState({
        selectedRowKeys,
        selectedItem
      })
    }
  }
}